package com.whfc.common.third.szyc.car;

import com.whfc.common.util.ByteUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2021-12-10 12:51
 */
public class DataUtil {

    /**
     * 车辆数据解码
     *
     * @param data
     * @return
     */
    public static String decode(String data) {
        byte[] bytes = data.getBytes();
        ByteBuf buf = Unpooled.buffer();
        for (int i = 0; i < bytes.length - 2; i++) {
            if ('%' == bytes[i]) {
                String temp = data.substring(i + 1, i + 3);
                buf.writeByte(ByteUtil.fromHexString(temp));
                i += 2;
            } else {
                buf.writeByte(bytes[i]);
            }
        }
        CharSequence s = buf.readCharSequence(buf.readableBytes(), Charset.forName("UTF8"));
        return s.toString();
    }

    public static void main(String[] args) {
        String data = "%7B%22outpicturedata%22%3A%22%22%2C%22outtime%22%3A%222021-12-10+12%3A06%3A51%22%2C%22workstationid%22%3A1%2C%22VLP%22%3A%22%E7%B2%A4A222222%22%2C%22consumefee%22%3A%220.00%22%2C%22method%22%3A%22%22%2C%22username%22%3A%22%22%2C%22Ctypename%22%3A%22%E4%B8%B4%E6%97%B6%E8%BD%A6%22%2C%22channeltype%22%3A0%2C%22operator%22%3A%22%E7%AE%A1%E7%90%86%E5%91%98%22%2C%22parkidinner%22%3A%220%22%2C%22inpicture1%22%3A%22%22%2C%22outpicturedata1%22%3A%22%22%2C%22direction%22%3A0%2C%22parkid%22%3A%221%22%2C%22inVLP%22%3A%22%22%2C%22remainspace%22%3A0%2C%22outchannel%22%3A1%2C%22Vtypename%22%3A%22%E5%B0%8F%E5%9E%8B%E8%BD%A6%22%2C%22parkkey%22%3A%22%22%2C%22parkname%22%3A%22%E4%B8%93%E4%B8%9AARM%E5%81%9C%E8%BD%A6%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F%22%2C%22cardsn%22%3A%22146097809901%22%2C%22inchannelname%22%3A%22AUTOBVT-3DKV39G%E5%85%A5%E5%8F%A31%22%2C%22outchannelname%22%3A%22AUTOBVT-3DKV39G%E5%85%A5%E5%8F%A31%22%2C%22Vtype%22%3A1%2C%22Vname%22%3A%22%22%2C%22receivablefee%22%3A%220.00%22%2C%22password%22%3A%22D41D8CD98F00B204E9800998ECF8427E%22%2C%22passmode%22%3A0%2C%22command%22%3A1%2C%22outpicture%22%3A%22%22%2C%22inchannel%22%3A1%2C%22totalspace%22%3A0%2C%22consumetime%22%3A%222021-12-10+12%3A06%3A51%22%2C%22consumename%22%3A%22%22%2C%22consumecode%22%3A0%2C%22intime%22%3A%222021-12-10+12%3A06%3A51%22%2C%22mode%22%3A0%2C%22code%22%3A1%2C%22groupid%22%3A0%2C%22recordid%22%3A7%2C%22outpicture1%22%3A%22%22%2C%22inpicturedata1%22%3A%22%22%2C%22Ctype%22%3A3%2C%22groupidupdate%22%3A0%2C%22ischarge%22%3A0%2C%22inpicturedata%22%3A%22%22%2C%22inpicture%22%3A%22001_01_L_11_I_6097809901_20211210120651.jpg%22%2C%22actualfee%22%3A%220.00%22%7D";
        System.out.println(decode(data));
    }
}
